home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / pcr / pcr4_4.lha / DIST / debugnub / CirioNubInnerProcs.c < prev    next >
C/C++ Source or Header  |  1992-04-16  |  8KB  |  310 lines

  1. /* begincopyright
  2.   Copyright (c) 1988-1992 Xerox Corporation. All rights reserved.
  3.   Use and copying of this software and preparation of derivative works based
  4.   upon this software are permitted. Any distribution of this software or
  5.   derivative works must comply with all applicable United States export
  6.   control laws. This software is made available AS IS, and Xerox Corporation
  7.   makes no warranty about the software, its performance or its conformity to
  8.   any specification. Any person obtaining a copy of this software is requested
  9.   to send their name and post office or electronic mail address to:
  10.     PCR Coordinator
  11.     Xerox PARC
  12.     3333 Coyote Hill Rd.
  13.     Palo Alto, CA 94304
  14.   endcopyright */
  15.  
  16. /*
  17.  * CirioNubInnerProcs.c
  18.  *
  19.  * Demers, February 25, 1992 11:40:39 am PST
  20.  *
  21.  * Utilities shared between local and server procs.
  22.  * Never lock the load state.
  23.  */
  24.  
  25. #include "xr/Errno.h"
  26. #include "xr/Threads.h"
  27. #include "xr/ThreadsBackdoor.h"
  28. #include "xr/IncrementalLoad.h"
  29. #include "xr/CirioNubInnerProcs.h"
  30.  
  31.  
  32. int
  33. CirioNubInnerGetThread(index, buf)
  34.     int index;
  35.     CirioNubThreadData buf;
  36. {
  37.     XR_Thread t;
  38.     int realIndex;
  39.  
  40.     realIndex = ((index >= 0) ? index : (-index));
  41.     if( realIndex >= XR_maxThreads ) return (-1);
  42.     t = &(XR_sysArea->sa_threadPool[realIndex]);
  43.     if( (t->t_sStat <= XR_SSTAT_FREE) && (index >= 0) ) return(-1);
  44.     buf->cntd_index = realIndex;
  45.     buf->cntd_gen = t->t_gen;
  46.     buf->cntd_sStat = t->t_sStat;
  47.     buf->cntd_pri = t->t_pri;
  48.     buf->cntd_dbMsg = t->t_dbMsg;
  49.     buf->cntd_dbFrozen = t->t_dbFrozen;
  50.     buf->cntd_pc = XR_SAVED_PC(t);
  51.     buf->cntd_fp = NIL; buf->cntd_sp = NIL;
  52.     XR_GET_SAVED_FRAME(t,(buf->cntd_fp),(buf->cntd_sp));
  53.     return 0;
  54. }
  55.  
  56.  
  57. /*
  58.  * "Real Name" heuristic -- because we generate lots of ugly names
  59.  *   of the form "cedarCc47From31415926.c2c.o"
  60.  */
  61.  
  62. static bool
  63. LooksLikeRealName(name)
  64.     char *name;
  65. {
  66.     int digitRun = 0;
  67. #   define MAXDIGITRUNINREALNAME 5
  68.     char c;
  69.  
  70.     if( name == NIL ) return FALSE;
  71.  
  72.     for(;;) {
  73.         if( (c = *name++) == 0 ) return TRUE;
  74.         if( (c >= '0') && (c <= '9') ) {
  75.             if( ++digitRun > MAXDIGITRUNINREALNAME ) return FALSE;
  76.         } else {
  77.             digitRun = 0;
  78.         }
  79.     }
  80. }
  81.  
  82.  
  83. static XR_ILSymEntry
  84. CirioNubInnerImproveEmbeddedFileNameGuess(ilseFN)
  85.     XR_ILSymEntry ilseFN;
  86. {
  87.     XR_ILSymEntry ilseTemp = ilseFN;
  88.     for(;;) {
  89.         if( LooksLikeRealName(ilseTemp->ilse_name) ) return ilseTemp;
  90.         ilseTemp = XR_ILGetMatchingSymEntryByValue(
  91.             /*prev ilse*/    ilseTemp,
  92.             /*value*/        0, /*ignored*/
  93.             /*wantedTypes*/    ILSE_MODULE,
  94.             /*ignoredClasses*/    IGNORE_NONE,
  95.             /*numToSkip*/    (-1)
  96.         );
  97.         if( (ilseTemp == NIL)
  98.                 || (ilseTemp->ilse_value != ilseFN->ilse_value) ) {
  99.             return ilseFN;
  100.         }
  101.     }
  102. }
  103.  
  104. int
  105. CirioNubInnerPCtoInfo(pc, buf)
  106.     XR_Pointer pc;
  107.     CirioNubPCInfo buf;
  108. {
  109.     XR_ILSymEntry ilse;
  110.     unsigned argValue;
  111.     XR_ILSymEntry ilseProc = NIL;
  112.     XR_ILSymEntry ilseFN = NIL;
  113.     XR_ILFileEntry ilfe = NIL;
  114.     
  115.     ilse = XR_ILGetMatchingSymEntryByValue(
  116.             /*prev ilse*/    NIL,
  117.             /*value*/        pc,
  118.             /*wantedTypes*/    WANT_ALL_TYPES,
  119.             /*ignoredClasses*/    IGNORE_NONE,
  120.             /*numToSkip*/    0
  121.         );
  122.     if( ilse == NIL ) goto Out;
  123.  
  124.     switch( ilse->ilse_type & (~ILSE_EXT) ) {
  125.         case ILSE_PATCH:
  126.             ilseProc = ilse;
  127.             ilfe = ilse->ilse_ilfe;
  128.             goto Out;
  129.         case ILSE_MODULE:
  130.             ilseFN = ilse;
  131.             ilfe = ilse->ilse_ilfe;
  132.             goto Out;
  133.         case ILSE_TEXT:
  134.             ilseProc = ilse;
  135.             ilfe = ilse->ilse_ilfe;
  136.             break;
  137.         default:
  138.             goto Out;
  139.     }
  140.  
  141.     ilse = XR_ILGetMatchingSymEntryByValue(
  142.             /*prev ilse*/    ilse,
  143.             /*value*/        0, /* ignored */
  144.             /*wantedTypes*/    ILSE_MODULE,
  145.             /*ignoredClasses*/    IGNORE_NONE,
  146.             /*numToSkip*/    0
  147.         );
  148.     if( (ilse != NIL)
  149.             && (ilse->ilse_ilfe == ilseProc->ilse_ilfe)
  150.             && ((ilse->ilse_value+ilse->ilse_size) > ilseProc->ilse_value) ) {
  151.         ilseFN = ilse;
  152.     }
  153.  
  154.   Out:
  155.  
  156.     if( ilseProc != NIL ) {
  157.         buf->procName = ilseProc->ilse_name;
  158.         buf->procSymID = ((unsigned)(ilseProc));
  159.     } else {
  160.         buf->procName = "";
  161.         buf->procSymID = 0;
  162.     }
  163.     if( ilfe != NIL ) {
  164.         buf->fileName = ilfe->ilfe_fName;
  165.         buf->fileSeqNum = ilfe->ilfe_seqNum;
  166.     } else {
  167.         buf->fileName = "";
  168.         buf->fileSeqNum = 0;
  169.     }
  170.     if( ilseFN != NIL ) {
  171.         ilseFN = CirioNubInnerImproveEmbeddedFileNameGuess(ilseFN);
  172.         buf->guessedEmbeddedFileName = ilseFN->ilse_name;
  173.         buf->guessedEmbeddedFileSymID = ((unsigned)(ilseFN));
  174.     } else {
  175.         buf->guessedEmbeddedFileName = "";
  176.         buf->guessedEmbeddedFileSymID = 0;
  177.     }
  178.  
  179.     return 0;
  180. }
  181.  
  182.  
  183.  
  184. int
  185. CirioNubInnerGetFileEntry(seqNum, buf)
  186.     unsigned seqNum;
  187.     CirioNubFileEntry buf;
  188. {
  189.     XR_ILFileEntry ilfe = NIL;
  190.  
  191.     for(;;) {
  192.         if( (ilfe = XR_ILGetPrevFileEntry(ilfe)) == NIL )
  193.             return(-1);    /* "can't hapen" */
  194.         if( ilfe->ilfe_seqNum <= seqNum ) break;
  195.     }
  196.     buf->seqNum = ilfe->ilfe_seqNum;
  197.     buf->commitPoint = ilfe->ilfe_commitPoint;
  198.     buf->fileName = ilfe->ilfe_fName;
  199.     buf->fOffset = ilfe->ilfe_fOffset;
  200.     buf->fMagic = ilfe->ilfe_fMagic;
  201.     buf->size = ilfe->ilfe_fSize;
  202.     buf->mTime = ilfe->ilfe_fMTime;
  203.     buf->sMagic = ilfe->ilfe_vMagic;
  204.     buf->stamp = ((XR_Pointer)(ilfe->ilfe_vStamp));
  205.     buf->stampSize = ilfe->ilfe_vLen;
  206.     buf->readerData = ((XR_Pointer)(ilfe->ilfe_rdrData));
  207.     buf->readerDataSize = ilfe->ilfe_rdrDataBytes;
  208.     buf->patchReloc = ((XR_Pointer)(ilfe->ilfe_pAddr));
  209.     buf->patchSize = ilfe->ilfe_pBytes;
  210.     buf->textReloc = ((XR_Pointer)(ilfe->ilfe_tAddr));
  211.     buf->textSize = ilfe->ilfe_tBytes;
  212.     buf->dataReloc = ((XR_Pointer)(ilfe->ilfe_dAddr));
  213.     buf->dataSize = ilfe->ilfe_dBytes;
  214.     buf->bssReloc = ((XR_Pointer)(ilfe->ilfe_bAddr));
  215.     buf->bssSize = ilfe->ilfe_bBytes;
  216.     buf->commonReloc = ((XR_Pointer)(ilfe->ilfe_cAddr));
  217.     buf->commonSize = ilfe->ilfe_cBytes;
  218.     return 0;
  219. }
  220.  
  221.  
  222.  
  223.  
  224. static void
  225. CirioNubInnerCopySymEntry(ilse, buf)
  226.     XR_ILSymEntry ilse;
  227.     CirioNubSymEntry buf;
  228. {
  229.     buf->symID = ((unsigned)(ilse));
  230.     buf->name = ilse->ilse_name;
  231.     buf->type = ilse->ilse_type;
  232.     buf->value = ilse->ilse_value;
  233.     buf->size = ilse->ilse_size;
  234.     buf->fileSeqNum = ilse->ilse_ilfe->ilfe_seqNum;
  235. }
  236.  
  237.  
  238. int
  239. CirioNubInnerGetMatchingSymEntryByName(
  240.     symID, pattern, caseSensitive, wantedTypes, ignoredClasses,
  241.     numToSkip, buf
  242. )
  243.     unsigned symID;
  244.     char *pattern;
  245.     bool caseSensitive;
  246.     unsigned wantedTypes;
  247.     unsigned ignoredClasses;
  248.     int numToSkip;
  249.     CirioNubSymEntry buf;
  250. {
  251.     XR_ILSymEntry ilse;
  252.  
  253.     ilse = XR_ILGetMatchingSymEntryByName(
  254.             ((XR_ILSymEntry)(symID)),
  255.             pattern,
  256.             caseSensitive,
  257.             wantedTypes,
  258.             ignoredClasses,
  259.             numToSkip
  260.         );
  261.     if( ilse == NIL ) return (-1);
  262.     CirioNubInnerCopySymEntry(ilse, buf);
  263.     return 0; 
  264. }
  265.  
  266.  
  267. int
  268. CirioNubInnerGetMatchingSymEntryByValue (
  269.     symID, val, wantedTypes, ignoredClasses, numToSkip, buf
  270. )
  271.     unsigned symID;
  272.     unsigned val;
  273.     unsigned wantedTypes;
  274.     unsigned ignoredClasses;
  275.     int numToSkip;
  276.     CirioNubSymEntry buf;
  277. {
  278.     XR_ILSymEntry ilse;
  279.  
  280.     ilse = XR_ILGetMatchingSymEntryByValue(
  281.             ((XR_ILSymEntry)(symID)),
  282.             val,
  283.             wantedTypes,
  284.             ignoredClasses,
  285.             numToSkip
  286.         );
  287.     if( ilse == NIL ) return (-1);
  288.     CirioNubInnerCopySymEntry(ilse, buf);
  289.     return 0; 
  290. }
  291.  
  292.  
  293.  
  294. int
  295. CirioNubInnerGetInstrSetAndOpSys(buf)
  296.     CirioNubInstrSetAndOpSys buf;
  297. {
  298. #   if defined(AIX)
  299.         buf->instrSet = "RS6000";
  300.         buf->opSys = "AIX";
  301. #   elif defined(SUNOS4X)
  302.         buf->instrSet = "SPARC";
  303.         buf->opSys = "SunOS4";
  304. #   else
  305.         --> error os ? <--
  306. #   endif
  307.     return 0;
  308. }
  309.  
  310.